<#assign base=request.contextPath />
<!DOCTYPE html>
<html>
<head>
  <base href="${base}">	
  <meta charset="utf-8">
  <title>角色授权</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="${base}/layuiadmin/layui/css/layui.css" media="all">
</head>

<body>
  	<div class="layui-form" lay-filter="LAY-form-list">
  		<input type="hidden" name="roleId" value="${role.roleId!}">
  		<blockquote class="layui-elem-quote">为角色『${role.roleName}』授权：</blockquote>  		
  		
    	<div class="layui-form-item">
	        <div style="margin-left: 20px">
	            <div id="LAY-auth-tree"></div>
	        </div>
    	</div>
    	
	    <div class="layui-form-item layui-hide">
	      	<input type="button" lay-submit lay-filter="LAY-form-submit" id="LAY-form-submit" value="确认添加">
	      	<input type="button" lay-submit lay-filter="LAY-form-edit" id="LAY-form-edit" value="确认编辑">
	    </div>
  	</div>

  <script src="${base}/layuiadmin/layui/layui.js"></script>  
  <script>
  	layui.config({
    	base: '${base}/layuiadmin/' //静态资源所在路径
  	}).extend({
    	index: 'lib/index',
    	jwt: '{/}${base}/js/lib/jwt',
    	authtree: '{/}${base}/js/lib/authtree'
  	}).use(['index', 'form', 'jwt', 'authtree'], function(){
    	var $ = layui.$;
    	var form = layui.form;
    	var jwt = layui.jwt;
    	var authtree = layui.authtree;
    	
    	jwt.ajax({
    		url: '${base}/system/role/grantXml?roleId=${role.roleId}',
    		success: function(data) {
    			var trees = data.data.trees;
    			// 取得数据
    	    	authtree.render('#LAY-auth-tree', trees, {
    				inputname: 'authids', 
    				layfilter: 'lay-check-auth', 
    				autowidth: true,
    			});
    	    	authtree.showDept('#LAY-auth-tree', 2);
    		}    		
    	});
    	       
    
    	//监听提交
    	form.on('submit(LAY-form-submit)', function(data) {
    		var checkVal = authtree.getChecked('#LAY-auth-tree');
    		var params = {
    			roleId: data.field.roleId,
    			rights: checkVal.join(',')
    		}
      		var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
      		//提交ajax成功后，关闭当前弹层并重载表格
      		jwt.ajax({
      			url: '${base}/system/role/grant',
      			data: params,
      			success: function(json) {
      				parent.layui.table.reload('LAY-table'); //重载表格
      	      		parent.layer.close(index); //再执行关闭      				
      			}
      		});
    	});
  	})
  </script>
</body>
</html>